import { createRouter, createWebHistory } from 'vue-router';

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    component: () => import('@/views/login.vue'),
  },
  {
    path: '/chinaMap',
    component: () => import('@/views/daohang02/chinaMap.vue'),
  },
  {
    path: '/index',
    component: () => import('@/views/index.vue'),
    redirect: '/index/home',
    children: [
      {
        path: '/index/home',
        component: () => import('@/views/home'),
      },
      {
        path: '/index/daohang01',
        children: [
          {
            path: '/index/daohang01/myPhoto',
            component: () => import('@/views/daohang01/myPhoto.vue'),
          },
          {
            path: '/index/daohang01/f',
            component: () => import('@/views/daohang01/f.vue'),
          },
        ]
      },
      {
        path: '/index/daohang02',
        children: [
          {
            path: '/mycharts01',
            component: () => import('@/views/daohang02/mycharts01.vue'),
          },

        ],
      },
      {
        path: '/index/daohang03',
        children: [
          {
            path: '/html',
            component: () => import('@/views/daohang03/html.vue'),
          },
          {
            path: '/css',
            component: () => import('@/views/daohang03/css.vue'),
          },
          {
            path: '/git',
            component: () => import('@/views/daohang03/git.vue'),
          },
          {
            path: '/js',
            component: () => import('@/views/daohang03/js.vue'),
          },

        ],
      },

    ]
  },
  // {
  //   path: '/daohang01',
  //   redirect:'/daohang01/myPhoto',
  //   children: [
  //     {
  //       path: '/daohang01/myPhoto',
  //       component: () => import('@/views/daohang01/myPhoto'),
  //     }
  //   ]
  // },
  // {
  //   path: '/about',
  //   component: () => import('@/views/about.vue')
  // }
];

const router = createRouter({
  history: createWebHistory(),
  routes
});
router.beforeEach((to, from, next) => {
  if (to.path == '/' || to.path == '/login') {
    next(); // 调用 next() 表示继续路由切换
  } else if (sessionStorage.user) {
    next()
  } else[
    next('/login')
  ]

  // 在路由切换之前执行的逻辑
  // 可以根据需要决定是否允许路由切换，或者执行其他操作
});
export default router;